/*
 * Copyright (c) 2006-2021, Halo team
 *
 * SPDX-License-Identifier: GPLv3
 *
 * Change Logs:
 * Date           Author       Notes
 * 2021-09-11     Eywen        the first version
 */


#ifndef FILAMENT_RUNOUT_H
#define FILAMENT_RUNOUT_H

#include "common.h"
#include "motion_step.h"

typedef enum filament_runout_st{      /* 断料检测状态 */
    filament_runout_st_normal,        /* 有料状态 */
    filament_runout_st_break,         /* 断料状态 */
}filament_runout_status_t;

typedef enum filament_runout_error{
    filament_runout_ok = 0,             /* 无错误 */
    filament_runout_err_uninit,         /* 未初始化 */
    filament_runout_err_short,          /* 短路 */
    filament_runout_err_break,          /* 断路 */
    filament_runout_err_unkown,         /* 未知错误 */
}filament_runout_err_t;

typedef struct _filament_runout filament_runout_t;

typedef struct _filament_runout_ops
{
    bool (*init)(filament_runout_t *device, int pin, bool release_level,
                 motion_step_t *step);
    filament_runout_status_t     (*status)(filament_runout_t *device);
    filament_runout_err_t        (*error)(filament_runout_t *device);
}filament_runout_ops_t;

typedef struct _filament_runout{
    int pin;                  		 	/* 引脚号 */
    bool normal_level;   		 		/* 正常时电平 */
    filament_runout_ops_t *ops;         /* 接口函数 */
    filament_runout_err_t err_status;   /* 错误状态 */
    filament_runout_status_t status;    /* 断料状态 */

    motion_step_t *motion_step_relevancy;  /* 关联的步进电机,在触发时可以重置步进电机
                                            位置信息 */
}filament_runout_t;



#endif // FILAMENT_RUNOUT_H
